﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;
using System.Diagnostics;
using nGSO.Performance;

namespace nGSO.UI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            ProcessModule main = Process.GetCurrentProcess().MainModule;
            Text = main.ModuleName + " " + main.FileVersionInfo.ProductVersion ;

            btnAnalytics.Enabled = true;

            cbxDataSources.ComboBox.DataSource = PerfDatabase.GetDatabases();
            cbxDataSources.ComboBox.DisplayMember = "Name";
            cbxDataSources.ComboBox.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);

            //Environment.SetEnvironmentVariable("PROCESSOR_ARCHITEW6432", string.Empty);
        }

        void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selFile = cbxDataSources.SelectedItem as FileInfo;

            PerfDatabase.SelectedDatabaseFileName = selFile.Name.Replace("selFile.Extension", string.Empty) ;
        }


        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            GsoTab tab = new GsoTab();
            tab.Dock = DockStyle.Fill;
            TabPage page = new TabPage() { Text = "Experiment " + tcGsoPanels.TabCount + " ... " };

            page.Controls.Add(tab);
            
            tcGsoPanels.Controls.Add(page);
            tcGsoPanels.SelectTab(page);
        }

        private void btnAnalytics_Click(object sender, EventArgs e)
        {
            AnalyticsWindow window = new AnalyticsWindow();
            window.ShowDialog();
            
            
        }

        private void btnKnapsackProblem_Click(object sender, EventArgs e)
        {
            TabPage page = new TabPage("GSO KP Probelm");
            KPPanel kpPanel = new KPPanel() { Dock= DockStyle.Fill };
            page.Controls.Add(kpPanel);
            tcGsoPanels.Controls.Add(page);
            tcGsoPanels.SelectedTab = page;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            KPRaport kpReport = new KPRaport();
            kpReport.ShowDialog();
        }

        private void btnClearDb_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Clear ALL performance results?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                PerfDatabase.ClearAllResults();

                MessageBox.Show("Database cleared", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
        }
    }
}
